var xlsx = require('node-xlsx');
const fs = require('fs');
const path = require('path');
const global = require(path.join(__dirname, './global.json'));

// 解析得到文档中的所有 sheet
var sheets = xlsx.parse(path.join(__dirname, './lang.xlsx'));
const data = sheets[0].data;
const keys = [];
const addGlobal = [];
const newData = [];

data?.forEach((item, index) => {
  if (!item[0]) return;
  newData.push(item);
  keys.push(item[0]);
});

global?.forEach((item, index) => {
  if (keys.includes(item)) return console.log('重复-->', item);
  addGlobal.push([item]);
});

const xlsxObj = [
  {
    name: 'lang',
    data: [...newData, ...addGlobal],
  },
];

fs.writeFileSync(path.join(__dirname, './lang.xlsx'), xlsx.build(xlsxObj), 'binary');
